 import CryptoJS from "crypto-js"
 export default {
   //加密
   encrypt(word, keyStr) {
     // 当未输入秘钥时，以下代码设置默认的秘钥
     keyStr = keyStr ? keyStr : 'abcdefgabcdefg12';
     var key = CryptoJS.enc.Utf8.parse(keyStr);
     var srcs = CryptoJS.enc.Utf8.parse(word);
     var encrypted = CryptoJS.AES.encrypt(srcs, key, {
       mode: CryptoJS.mode.ECB,
       padding: CryptoJS.pad.Pkcs7
     });
     return encrypted.toString();
 
   },
   //解密
   decrypt(word, keyStr) {
     // 当未输入秘钥时，以下代码设置默认的秘钥
     keyStr = keyStr ? keyStr : 'abcdefgabcdefg12';
     var key = CryptoJS.enc.Utf8.parse(keyStr);
     var decrypt = CryptoJS.AES.decrypt(word, key, {
       mode: CryptoJS.mode.ECB,
       padding: CryptoJS.pad.Pkcs7,
     });
     return decrypt.toString(CryptoJS.enc.Utf8).toString();
   },
   //生成AES 16位秘钥
   getKey() {
     let len = 16;
     let chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz1234567890';
     let maxPos = chars.length;
     let character = '';
     for (let i = 0; i < len; i++) {
       character += chars.charAt(Math.floor(Math.random() * maxPos))
     }
     return character;
   }
 }